﻿<Window x:Class="Yamaha.AVControl.Desktop.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:con="clr-namespace:Yamaha.AVControl.Desktop.Controls"
        xmlns:mod="clr-namespace:Yamaha.AVControl.Desktop.Models"
        Icon="Images/Icon.ico"
        ResizeMode="NoResize"
        WindowStyle="SingleBorderWindow"
        Title="Yamaha AV Control" Height="415" Width="415">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styles\DefaultTheme.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <mod:SelectionModeBoolenConverter x:Key="convZone" VisibleMode="Zone" InvisibleMode="None" />
            <mod:SelectionModeBoolenConverter x:Key="convInput" VisibleMode="Input" InvisibleMode="None" />
            <mod:SelectionModeBoolenConverter x:Key="convDSP" VisibleMode="DSP" InvisibleMode="None" />
            <mod:SelectionModeBoolenConverter x:Key="convScene" VisibleMode="Scene" InvisibleMode="None" />
            <con:BooleanVisibilityConverter x:Key="invCov" FalseVisibility="Visible" TrueVisibility="Collapsed" />
            <con:BooleanInverterConverter x:Key="inverter" />
        </ResourceDictionary>
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <Grid DockPanel.Dock="Bottom" x:Name="btnGrid" Background="{StaticResource LineSeperatorBrush}">
            <Grid.Resources>
                <Style TargetType="Button">
                    <Setter Property="Height" Value="50" />
                </Style>
                <Style TargetType="Image" x:Key="imgSty">
                    <Setter Property="Height" Value="24" />
                    <Setter Property="Width" Value="24" />
                </Style>
                <Style TargetType="TextBlock">
                    <Setter Property="Foreground" Value="{StaticResource TextForeground}" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Setter Property="Margin" Value="10,0" />
                </Style>
                <Style TargetType="Border">
                    <Setter Property="Background" Value="White" />
                    <Setter Property="BorderBrush" Value="{StaticResource DarkBlue}" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="Opacity" Value="0.97" />
                </Style>
                <Style TargetType="Popup">
                    <Setter Property="AllowsTransparency" Value="True" />
                    <Setter Property="Placement" Value="Center" />
                    <Setter Property="PlacementTarget" Value="{Binding ElementName=theZoneView}" />
                    <Setter Property="PopupAnimation" Value="Slide" />
                    <Setter Property="Height" Value="{Binding ElementName=theZoneView, Path=ActualHeight}" />
                    <Setter Property="Width" Value="{Binding ElementName=theZoneView, Path=ActualWidth}" />
                </Style>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <ToggleButton Grid.Column="0" 
                          IsEnabled="{Binding IsConnected}"
                          IsChecked="{Binding Path=SelectionMode, Converter={StaticResource convZone}}"
                          Style="{StaticResource ClearToggleButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="{StaticResource IMG_ZONES}" Style="{StaticResource imgSty}" />
                    <TextBlock Text="Zones" />
                </StackPanel>
            </ToggleButton>
            <ToggleButton Grid.Column="1" 
                          IsEnabled="{Binding SelectedZone.IsOn}"
                          IsChecked="{Binding Path=SelectionMode, Converter={StaticResource convInput}}"
                          Style="{StaticResource ClearToggleButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="{StaticResource IMG_INPUTS}" Style="{StaticResource imgSty}" />
                    <TextBlock Text="Inputs" />
                </StackPanel>
            </ToggleButton>
            <ToggleButton Grid.Column="2" 
                          IsEnabled="{Binding SelectedZone.IsOn}"
                          IsChecked="{Binding Path=SelectionMode, Converter={StaticResource convScene}}"
                          Style="{StaticResource ClearToggleButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="{StaticResource IMG_SCENE}" Style="{StaticResource imgSty}" />
                    <TextBlock Text="Scene" />
                </StackPanel>
            </ToggleButton>

            <Popup IsOpen="{Binding Path=SelectionMode, Converter={StaticResource convZone}}">
                <Border>
                    <con:SelectorView DataContext="{Binding Zones}" />
                </Border>
            </Popup>
            <Popup IsOpen="{Binding Path=SelectionMode, Converter={StaticResource convInput}}">
                <Border>
                    <con:SelectorView DataContext="{Binding Inputs}" />
                </Border>
            </Popup>
            <Popup IsOpen="{Binding Path=SelectionMode, Converter={StaticResource convScene}}">
                <Border>
                    <con:SelectorView DataContext="{Binding Scenes}" />
                </Border>
            </Popup>
            <Popup x:Name="puConnect" IsOpen="{Binding IsConnected, Converter={StaticResource inverter}}">
                <Border>
                    <DockPanel>
                        <TextBlock DockPanel.Dock="Bottom" Foreground="Black"
                                Text="{Binding Version}" FontSize="12" TextAlignment="Right" HorizontalAlignment="Right" />
                        <Border HorizontalAlignment="Center" VerticalAlignment="Center" 
                            Background="{StaticResource LineSeperatorBrush}">
                            <DockPanel LastChildFill="True">
                                <TextBlock FontSize="14" FontWeight="Bold" Foreground="Black"
                                    Text="Reciever Host Name or IP Address"
                                    DockPanel.Dock="Top" />
                                <Button Margin="10,5" Click="Connect_Click" IsDefault="True"
                                    Style="{StaticResource DefaultButton}" HorizontalAlignment="Center" HorizontalContentAlignment="Center"
                                         DockPanel.Dock="Bottom">
                                    <TextBlock Text="Connect" TextAlignment="Center" Foreground="Black" />
                                </Button>
                                <TextBox x:Name="tbHost" TextAlignment="Center" Text="192.168.0.103" FontSize="20" />
                            </DockPanel>
                        </Border>
                    </DockPanel>
                </Border>
            </Popup>
            <Popup x:Name="puDialog">
                <Border>
                    <Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="{StaticResource LineSeperatorBrush}">
                        <DockPanel LastChildFill="True">
                            <TextBlock FontSize="14" FontWeight="Bold" Foreground="Black"
                                    Text="Invalid Host Please try again."
                                    DockPanel.Dock="Top" />
                            <ToggleButton x:Name="puOkButton"
                                    Margin="10,5" IsChecked="{Binding ElementName=puDialog, Path=IsOpen, Converter={StaticResource inverter}}"
                                    Style="{StaticResource DefaultToggleButton}" 
                                    HorizontalAlignment="Center" HorizontalContentAlignment="Center"
                                         DockPanel.Dock="Bottom">
                                <TextBlock Text="OK" TextAlignment="Center" Foreground="Black" />
                            </ToggleButton>
                        </DockPanel>
                    </Border>
                </Border>
            </Popup>
        </Grid>
        <con:ZoneView x:Name="theZoneView" DataContext="{Binding SelectedZone}" Margin="3,1,3,3" Padding="10" />
    </DockPanel>
</Window>
